﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ewk.Math.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Math.ComputationTypes.UnitTests
{
    [TestClass]
    public class ComputableComplexUnitTests
    {
        [TestMethod]
        public void ComputableComplex_can_be_added_to_another_ComputableComplex()
        {
            var a = Computable<Complex>.Factory.Create(new Complex(12, 1));
            var b = Computable<Complex>.Factory.Create(new Complex(3, 5));

            var c = a + b;

            Assert.AreEqual(15.0, c.Value.Real);
            Assert.AreEqual(6.0, c.Value.Imaginary);
        }

        [TestMethod]
        public void ComputableComplex_can_be_subtracted_from_another_ComputableComplex()
        {
            var a = Computable<Complex>.Factory.Create(new Complex(12, 1));
            var b = Computable<Complex>.Factory.Create(new Complex(3, 5));

            var c = a - b;

            Assert.AreEqual(9.0, c.Value.Real);
            Assert.AreEqual(-4.0, c.Value.Imaginary);
        }

        [TestMethod]
        public void ComputableComplex_can_be_multiplied_by_another_ComputableComplex()
        {
            var a = Computable<Complex>.Factory.Create(new Complex(12, 1));
            var b = Computable<Complex>.Factory.Create(new Complex(3, 5));

            var c = a * b;

            Assert.AreEqual(31.0, c.Value.Real);
            Assert.AreEqual(63.0, c.Value.Imaginary);
        }

        [TestMethod]
        public void ComputableComplex_AlmostEqual_returns_true_when_two_instances_of_One_Computable_are_compared()
        {
            var value1 = Computable<Complex>.Factory.One;
            var value2 = Computable<Complex>.Factory.One;

            Assert.IsFalse(ReferenceEquals(value1, value2));
            Assert.IsTrue(value1.AlmostEquals(value2));
        }

        [TestMethod]
        public void ComputableComplex_AlmostEqual_returns_true_when_an_instance_of_One_is_compared_to_an_instances_of_almost_One()
        {
            var value1 = Computable<Complex>.Factory.One;
            var value2 = Computable<Complex>.Factory.One + Computable<Complex>.Factory.Epsilon;

            Assert.IsFalse(ReferenceEquals(value1, value2));
            Assert.IsTrue(value1.AlmostEquals(value2));
        }

        [TestMethod, Ignore]
        public void ComputableComplex_AlmostEqual_returns_false_when_two_instances_of_almost_One_Computable_are_compared()
        {
            var value1 = Computable<Complex>.Factory.One - Computable<Complex>.Factory.Epsilon;
            var value2 = Computable<Complex>.Factory.One + Computable<Complex>.Factory.Epsilon;

            Assert.IsFalse(ReferenceEquals(value1, value2));
            Assert.IsFalse(value1.AlmostEquals(value2));
        }
    }
}